<template>
  <q-btn class="btn margin-r-10" outline color="primary" @click="download" v-if="permission === null">{{label}}</q-btn>
  <q-btn class="btn margin-r-10" outline color="primary" @click="download" v-else v-has="{id: permission}">{{label}}</q-btn>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'download-btn',
  props: {
    label: {
      type: String,
      default: '下载模版'
    },
    url: Function,
    fileName: {
      type: String,
      default: '(模板).xls'
    },
    permission: {
      default: null
    }
  },
  methods: {
    // 模版下载
    download () {
      this.url().then(async res => {
        await this.$saveFileForBlob(res.data, this.fileName)
        this.$message.success('数据请求成功,请保存文件')
      })
    }
  },
  computed: {
    ...mapGetters([
      'client'
    ])
  }
}
</script>

<style scoped lang="stylus">

</style>
